//
//  ClientManager.m
//  Xinjuxin
//
//  Created by 廖挺 on 16/5/31.
//  Copyright © 2016年 liaoting. All rights reserved.
//

#import "ClientManager.h"

@implementation ClientManager

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    static id object = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        object = [super allocWithZone:zone];
    });
    return object;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        _userDefaults = [NSUserDefaults standardUserDefaults];
    }
    return self;
}

+ (instancetype)manager {
    return [[ClientManager alloc] init];
}

- (void)saveSessionToken:(NSString *)sessionToken {
    [_userDefaults setObject:sessionToken forKey:@"sessionToken"];
    [_userDefaults synchronize];
}

- (NSString *)getSessionToken {
    return [_userDefaults objectForKey:@"sessionToken"]?[_userDefaults objectForKey:@"sessionToken"]:@"";
}

- (void)saveAccessToken:(NSString *)accessToken {
    [_userDefaults setObject:accessToken forKey:@"accessToken"];
    [_userDefaults synchronize];
}

- (NSString *)getAccessToken {
    return [_userDefaults objectForKey:@"accessToken"]?[_userDefaults objectForKey:@"accessToken"]:@"";
}

- (void)saveRefreshToken:(NSString *)refreshToken {
    [_userDefaults setObject:refreshToken forKey:@"refreshToken"];
    [_userDefaults synchronize];
}

- (NSString *)getRefreshToken {
    return [_userDefaults objectForKey:@"refreshToken"]?[_userDefaults objectForKey:@"refreshToken"]:@"";
}


@end
